﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.Script.Services;
using System.IO;

namespace AjaxToolkitDemo
{
    public partial class SynamicPopulateExt : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod]
        [ScriptMethod]
        public static string GetDynamicContent(string contextKey)
        { 
           object  list ;
            switch (contextKey)
            {
                case "1":
                    list  = Customer.GetSampleData();
                    break;
                case "2":
                    list = Employee.GetSampleData();
                    break;
                default:
                    list = Product.GetSampleData();
                    break;
            }

            GridView myGrid = new GridView();
            myGrid.ID = "G1";
            myGrid.DataSource = list;
            myGrid.DataBind();
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            myGrid.RenderControl(htw);
            htw.Close();
            return sw.ToString();
        }
    }
}
